package week10;

import java.util.Scanner;

/**
 * @author The setting sun
 * @version 1.0
 * @title: bank
 * @description: TODO
 * @date 2021/11/10 9:41
 */
public class Work2 {
    public static void main(String[] args) {
        MyThread1 mt = new MyThread1();

        Thread t1 = new Thread(mt, "man");
        Thread t2 = new Thread(mt, "woman");

        t1.start();
        t2.start();
    }
}

class MyThread1 implements Runnable {
    int p = 1000;
    int a = 100;

    @Override
    public void run() {
        while (true){
            synchronized (this) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                if (p >= a) {
                    System.out.println(Thread.currentThread().getName() + "取出" + a + "元，剩余" + (p - a) + "元");
                    p = p - a;
                } else {
                    return;
                }
            }
        }

    }
}
